package com.shxzz.easy12306.framework.starter.idempotent.config;

import com.shxzz.easy12306.framework.starter.cache.DistributeCache;
import com.shxzz.easy12306.framework.starter.idempotent.core.IdempotentAspect;
import com.shxzz.easy12306.framework.starter.idempotent.core.handler.spel.IdempotentSpELByMQExecuteHandler;
import com.shxzz.easy12306.framework.starter.idempotent.core.handler.spel.IdempotentSpELByRestAPIExecuteHandler;
import org.redisson.api.RedissonClient;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;

/**
 * 幂等组件自动装配
 * @author shxzz
 * @create 2024-02-22-20:21
 */
public class IdempotentAutoConfiguration {
    @Bean
    public IdempotentAspect idempotentAspect() {
        return new IdempotentAspect();
    }

    @Bean
    @ConditionalOnMissingBean
    public IdempotentSpELByMQExecuteHandler idempotentSpELByMQExecuteHandler(DistributeCache distributeCache) {
        return new IdempotentSpELByMQExecuteHandler(distributeCache);
    }

    @Bean
    @ConditionalOnMissingBean
    public IdempotentSpELByRestAPIExecuteHandler idempotentSpELByRestAPIExecuteHandler(RedissonClient redissonClient) {
        return new IdempotentSpELByRestAPIExecuteHandler(redissonClient);
    }
}